<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=9" />
		<meta http-equiv="pragma" content="no-cache" />
		<title>新增菜单</title>
		<%@ include file="../../common/Admin-list.jsp"%>  		
		<script type="text/javascript" src="<%=bpath %>Scripts/jquery/jquery.form.js"></script> 			 
		<script type="text/javascript">	
		var IconSize=24; //一级 菜单 24 二级 32
		
		$(function(){
			var subUrl="../AdminMenu/save.json";			
			if('${data.type}'!=null&&'${data.type}'=="edit"){ //修改
				
				$("#lblTitle").html('修改菜单');
				$("input[name=visible]:eq(${data.admin_Menu.visible})").attr("checked",'checked');				
				$("#id").val('${data.admin_Menu.id}');
				$("#parentID").val('${data.admin_Menu.parentID}');
				$("#name").val('${data.admin_Menu.name}');				
				$("#url").val('${data.admin_Menu.url}');
				$("#icon").val('${data.admin_Menu.icon}');
				$("#sortID").val('${data.admin_Menu.sortID}');
				$("#levelID").val('${data.admin_Menu.levelID}');
				$("#is_deleted").val('${data.admin_Menu.is_deleted}');
				
				
				if('${data.admin_Menu.parentID}'!="0"){ //修改的是 子集
					IconSize=32;
				}
				var srcPath='<%=basePath %>pages/Admin/Images/Icon/'+IconSize+'/${data.admin_Menu.icon}';				
				$("#imgIcon").attr('src',srcPath);  
					
				subUrl="../AdminMenu/update.json";
			}else if('${data.type}'!=null&&'${data.type}'=="addSub"){ //新增子集
				
				$("#lblTitle").html('新增子集菜单');
				$("#parentID").val('${data.parentID}');
				$("#levelID").val('1');
				IconSize=32;
			}
			
			//判断是否 修改页面
			//if('${data.admin_Menu.id}'!=null && '${data.admin_Menu.id}'!=""){}	
			//是否新增子集 parentID			
			//if('${data.parentID}' !=null && '${data.parentID}'!=""){}
			
			
			//保存
			$("#lnbSave").click(function(){								
				$("#addForm").ajaxSubmit({
					url:subUrl,
					type:"POST",
					beforeSubmit:checkForm,
					contentType:"application/x-www-form-urlencoded;charset=UTF-8",
					error:function(){},
					success:function(data){
						if(data.success==true){
							showTip("保存成功，返回列表页面！","succeed");					    	
						}else{
							//showTip("操作失败","warning");  
							art.dialog.alert('保存失败，请确认填写正确！');
						}
					},
				});
			});
		});
			
		function checkForm(){
			var flag=$('#addForm').form('validate');
			return true;
		}
				
		//消息提示  
		function showTip(mess,icon) {  
		    art.dialog({  
		        id : 'Tip',  
		        title : '消息',  
		        fixed : true,  
		        lock : true,  
		        opacity: .2,  
		        content : mess,  
		        icon : icon,  
		        time : 1  
		    });  
		    setTimeout('originReload()', 1000);  
		}  
		
		//重载来源页面  
		function originReload(){  
		    var win = art.dialog.open.origin;		    
		    win.location.reload();  
		}
		
		function getIcon(index){  //选择图标
			art.dialog.open('../AdminMenu/iconInterface.htm?fileSize='+IconSize,{
				title: '选择菜单图标',
				lock:true,
			  	width:483,
			    height:314,
			    left:'0%',
			    top:'0%'
			});
      	}
		
		</script>
		
</head>
<body>
<!---->
<div>
	<div id="tab">
        <ul>
            <li class="Current">
            	<a href="#" onfocus="this.blur()">
            		<span id="lblTitle" >  新增菜单   </span>
            	</a>
            </li>
        </ul>
    </div>  
    <div id="menu">
        <ul>
            <li>
            	<a id="lnbSave"  onclick="lnbSave_Click">
            		<span><img src="<%=basePath %>pages/Admin/Images/Icon/save.gif" alt="Save" />保存</span>
            	</a>
            </li>
        </ul>
    </div>
    
    <div id="middle"> 
    <form action="../AdminMenu/save.json" id="addForm" name="addForm" method="post" >   
    <div class="editor">
        <table class="eTable">
            <tr class="eTr">
                <td class="name">
                    <label id="Label1" >显示状态</label>
                </td>
                <td>
                	<input type="radio" id="dazhuan" name="visible" value="0"/>关闭
					<input type="radio" id="benke" name="visible" value="1"/>开启
				</td>
            </tr>
            <tr class="eTr">
                <td class="name">
                    <label id="Label2" >菜单名称</label></td>
                <td>
                    <input id="name" name="name" class="input" ></input>
                    
                    <input id="id" name="id" type="text"></input>
                    <input id="parentID" name="parentID" type="text" value="0"></input>
                    <input id="levelID" name="levelID" type="hidden" value="0" ></input>
                    <input id="is_deleted" name="is_deleted" type="hidden" value="0" ></input>
                </td>
            </tr>         
            <tr class="eTr">
                <td class="name">
                    <label id="Label4">菜单路径</label></td>
                <td>
                    <input id="url" name="url" class="input"></input>
                    
                </td>
            </tr>
            <tr class="eTr">
                <td class="name">
                    <label id="Label5" >菜单排序</label></td>
                <td>
                    <input id="sortID" name="sortID" class="input" ></input>
                      
                    </td>
            </tr>
            <tr class="eTr">
                <td class="name">
                    <label id="Label6" >菜单图标</label></td>
                <td>
                    <input id="icon" name="icon" class="input" onclick="getIcon();" ></input>                                          
                </td>
            </tr>
        </table>
        <div id="iconDiv"><img id="imgIcon" /></div>
    </div>
    </form> 
    </div>
</div>
</body>
</html>